package com.weipai.education.service.impl;

import com.aliyuncs.exceptions.ClientException;
import com.weipai.education.enums.RetCode;
import com.weipai.education.model.api.Response;
import com.weipai.education.service.SmsService;
import com.weipai.education.utils.SessionUserUtil;
import com.weipai.education.utils.SmsHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author songmengqiang
 * @create 2018-09-13 17:28
 **/
@Service
public class SmsServiceImpl implements SmsService {

    private static final Logger logger = LoggerFactory.getLogger(SmsServiceImpl.class);
    
    @Override
    public Response sendCode(String phone) {
        Response response = new Response();
        //发送验证码
        String checkCode = null;
        try {
            checkCode = SmsHelper.sendCheckCode(phone);
            response.put("checkCode", checkCode);
            response.setCode(RetCode.SUCCESS);
        } catch (ClientException e) {
            response.setCode(RetCode.SMS_CODE_SEND_ERROR);
            logger.error("sendCheckCode to {} with error = {}", phone, e);
        }
        return response;
    }
    
}
